<?php

class Damages_Exception_App extends Damages_Exception_Core {

  const TYPE_INFO = 'information';
  const TYPE_ERROR = 'error';

  public function __construct($code, $args = null) {
    $config = Damages_Config::getInstance()->log;
    $filename = Zend_Controller_Front::getInstance()->getModuleDirectory() . $config->app->errorsFilename;
    if (!file_exists($filename))
      throw new Exception("File: " . $filename . " doesn't exist");
    $errorsXml = new Zend_Config_Xml($filename);
    $codeXml = 'e' . $code;
    $errorDef = $errorsXml->$codeXml;
    $this->type = $errorDef->type;
    $this->code = $code;
    $this->doLog = (bool) $config->app->power;
    $this->message = vsprintf($errorDef->system, $args);
    $this->userMessage = vsprintf($errorDef->user,$args);
    if (isset($errorDef->callback)){
      $this->callback = $errorDef->callback->toArray();
    }
    parent::__construct();
  }

}